<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ATM-模拟</title>
    <script src="sdk/jquery-1.10.min.js"></script>
    <style>
        body,html{
            margin: 0;
            height: 100%;
        }
        button{
            height: 85px;
            width: 200px;
            background-color: #d7d7d7;
            font-size: 20px;
            font-weight: bold;
            border: 0;
        }
        .content{
            color: white;
            font-weight: bold;
            font-size: 25px;
            margin: 0 auto;
            margin-top: 250px;
            width: max-content;
        }
    </style>
</head>
<body>
<div style="margin: 0 auto;overflow: hidden;height: 15%;">
    <div style="float: left;margin: 10px;">
        <img src="img/信工logo.jfif" width="100px" alt="banklogo">
    </div>
    <div style="float: left;margin-left: 10px;">
        <span style="font-size: 50px;font-weight: bold;">中国儿童银行</span>
        <br>
        <span style="font-size: 35px;font-weight: bold;">China Child Bank</span>
    </div>
</div>


<div style="background-color: #330099;overflow: hidden;height: 85%;">
    <div style="float:left;width: 15%">
        <button style="margin-top: 720px;border-bottom-right-radius: 10px;border-top-right-radius: 10px;box-shadow: 1px 1px 5px black;" onclick="backToIndex()">返回 <br> Back</button>
    </div>
    <div style="float: left;width: 70%">
        <div class="content">
            <span id="remainAmount"></span>
        </div>
    </div>
    <div style="float:right; width: 15%">
        <button onclick="deposit()" style="margin-top: 510px;border-bottom-left-radius: 10px;border-top-left-radius: 10px;box-shadow: -1px 1px 5px black;float: right">存款 <br> Deposit</button>
        <button onclick="cash()" style="margin-top: 125px;border-bottom-left-radius: 10px;border-top-left-radius: 10px;box-shadow: -1px 1px 5px black;float: right">取款 <br> Cash</button>
    </div>
</div>


<script>

    $(function (){

        $.ajax(
                {
                    url: "http://localhost:8888/atm/api/balance?token="+localStorage.getItem("token"),
                    type: "POST",
                    datatype: "json", // 返回的数据格式
                    success: function (res){
                        if (res.code === 10001){
                            alert("登录异常，请重新登录")
                            window.location = "./login.html"
                            return;
                        }
                        if(res.code!==200) {
                            alert("获取信息失败,"+res.message)
                            return
                        }
                        console.log("登录后账户信息", res.data)
                        $("#remainAmount").text('余额: ￥' + res.data.remainAmount / 100 )
                    },
                    error: function (){
                        alert("余额查询失败，服务器异常！")
                    }
                }
            )
    })

    function backToIndex() {
        window.location = "./index.html"
    }

    function deposit(){
        window.location = "./deposit.html"
    }

    function cash(){
        window.location = "./cash.html"
    }
</script>
</body>
</html>